#include "selfinfowidget.h"


SelfInfoWidget::SelfInfoWidget(QWidget *parent) : QDialog(parent)
{
    // 1. 设置基础属性
    this->setFixedSize(450, 250);
    this->setWindowIcon(QIcon("://resource/image/wechat.png"));
    this->setWindowTitle("个⼈信息");
    this->setAttribute(Qt::WA_DeleteOnClose);
    // 设置窗⼝显⽰位置为⿏标所在位置.
    this->move(QCursor::pos());
    // 设置背景⾊
    this->setStyleSheet("QWidget { background-color: rgb(255, 255, 255); font-size: 18px;} QPushButton { border: none; } QPushButton:pressed {background-color: rgb(235, 235, 235);}");

    // 2. 创建界⾯布局
    QHBoxLayout* layout = new QHBoxLayout();
    layout->setContentsMargins(30, 20, 30, 20);
    layout->setSpacing(10);
    this->setLayout(layout);

// 3. 添加⽤⼾头像
    avatar = new QPushButton();
    avatar->setFixedSize(75, 75);
    avatar->setIconSize(QSize(75, 75));
    avatar->setStyleSheet("QPushButton { border: none; background-color:white;}");
    layout->addWidget(avatar, 0, Qt::AlignTop);
    layout->addWidget(avatar, 0, Qt::AlignTop);
    // 4. 添加⽤⼾其他信息
    // 这⾥实现的效果是, 使⽤⼀个 N ⾏ 4 列的 gridLayout 表⽰布局
    // 第 0 列是⼀个 QLabel
    // 第 1 列是⼀个 QLineEdit
    // 第 2 列是⼀个 编辑按钮
    // 第 3 列是⼀个 确认按钮
    // 界⾯默认是显⽰ QLabel 和 编辑按钮.
    // 点击编辑之后, 就会切换成显⽰ QLineEdit 和 确认按钮.
    // 点击确认之后, ⼜会切换回 QLabel 和 编辑按钮.
    // (通过 hide 和 show 操作来切换).
    gridLayout = new QGridLayout();
    gridLayout->setContentsMargins(0, 0, 0, 0);
    gridLayout->setSpacing(10);
    layout->addLayout(gridLayout);

    // 作为下⽅输⼊框的宽度
    QSize size(200, 30);
    // 4.1 ⽤⼾ id (不能编辑, ⽆需切换)
    QLabel* idTag = new QLabel(this);
    idTag->setStyleSheet("QLabel { font-weight: 800; }");
    idTag->setText("序号");
    QLabel* idLabel = new QLabel(this);
    QIcon modifyIcon("://resource/image/modify.png");
    QIcon submitIcon("://resource/image/submit.png");

    // 4.2 ⽤⼾昵称
    QLabel* nameTag = new QLabel(this);
    nameTag->setText("昵称");
    nameTag->setStyleSheet("QLabel { font-weight: 800; }");
    nameLabel = new QLabel(this);
    nameLabel->setFixedSize(size);
    nameEdit = new QLineEdit(this);
    nameEdit->setFixedSize(size);
    nameModifyBtn = new QPushButton(this);
    nameModifyBtn->setIcon(modifyIcon);
    nameSubmitBtn = new QPushButton(this);
    nameSubmitBtn->setIcon(submitIcon);
    nameEdit->hide();
    nameSubmitBtn->hide();

    // 4.3 ⽤⼾签名
    QLabel* descTag = new QLabel(this);
    descTag->setText("签名");
    descTag->setStyleSheet("QLabel { font-weight: 800; }");
    descLabel = new QLabel(this);
    descLabel->setFixedSize(size);
    descEdit = new QLineEdit(this);
    descEdit->setFixedSize(size);
    descModifyBtn = new QPushButton(this);
    descModifyBtn->setIcon(modifyIcon);
    descSubmitBtn = new QPushButton(this);
    descSubmitBtn->setIcon(submitIcon);
    descEdit->hide();
    descSubmitBtn->hide();

    // 4.4 ⽤⼾电话
    QLabel* phoneTag = new QLabel(this);
    phoneTag->setText("电话");
    phoneTag->setStyleSheet("QLabel { font-weight: 800; }");
    phoneLabel = new QLabel(this);
    phoneLabel->setFixedSize(size);
    phoneEdit = new QLineEdit(this);
    phoneEdit->setFixedSize(size);
    phoneModifyBtn = new QPushButton(this);
    phoneModifyBtn->setIcon(modifyIcon);
    phoneSubmitBtn = new QPushButton(this);
    phoneSubmitBtn->setIcon(submitIcon);
    phoneEdit->hide();
    phoneSubmitBtn->hide();

    verityCodeEdit = new QLineEdit(this);
    verityCodeEdit->setFixedSize(size);
    verityCodeEdit->setPlaceholderText("验证码");
    verityCodeEdit->hide();
    // 通过这个按钮来显⽰发送间隔时间的倒计时.
    sendVerityCodeBtn = new QPushButton(this);
    sendVerityCodeBtn->setText("获取");
    sendVerityCodeBtn->hide();

#if TEST_UI
    avatar->setIcon(QIcon("://resource/image/defaultAvatar.jpg"));
    idLabel->setText("1234");
    nameLabel->setText("张三");
    descLabel->setText("从今天开始认真敲代码");
    phoneLabel->setText("18612345678");
#endif
    // 5. 添加到布局管理器中.
    gridLayout->setRowStretch(0, 1);
    gridLayout->setRowStretch(1, 1);
    gridLayout->setRowStretch(2, 1);
    gridLayout->setRowStretch(3, 1);
    gridLayout->setRowStretch(4, 1);

    gridLayout->addWidget(idTag, 0, 0);
    gridLayout->addWidget(idLabel, 0, 1);

    gridLayout->addWidget(nameTag, 1, 0);
    gridLayout->addWidget(nameLabel, 1, 1);
    gridLayout->addWidget(nameModifyBtn, 1, 2);

    gridLayout->addWidget(descTag, 2, 0);
    gridLayout->addWidget(descLabel, 2, 1);
    gridLayout->addWidget(descModifyBtn, 2, 2);

    gridLayout->addWidget(phoneTag, 3, 0);
    gridLayout->addWidget(phoneLabel, 3, 1);
    gridLayout->addWidget(phoneModifyBtn, 3, 2);

    gridLayout->addWidget(sendVerityCodeBtn, 4, 0);
    gridLayout->addWidget(verityCodeEdit, 4, 1);

    // 6. 设置第⼀⾏的 SizePolicy
    QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    idTag->setSizePolicy(sizePolicy);
    idLabel->setSizePolicy(sizePolicy);

}
